package com.frxuexi.visit.adapter

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.VisitBeanItem
import com.frxuexi.visit.R
import com.frxuexi.visit.databinding.ItemVisitBinding

class VisitAdapter:BaseQuickAdapter<VisitBeanItem,BaseViewHolder>(R.layout.item_visit) {
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemVisitBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: VisitBeanItem) {
        val binding=DataBindingUtil.getBinding<ItemVisitBinding>(helper.itemView)!!
        binding.bean=item

        binding.visitImg.apply {
            if(item.requestParking){
                setImageResource(com.frxuexi.lib_base.R.drawable.ic_action_car)
            }else{
                setImageResource(com.frxuexi.lib_base.R.drawable.ic_action_nocar)
            }
        }

        binding?.visitStatus?.apply {
            when(item.visitStatus){
                "待审核"->{
                    setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.orange))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_weihu)
                }
                "已完成"->{
                    setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.darkgray))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_lightgray)
                }
                "驳回"->{
                    setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.redfont))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_red)
                }
                else->{
                    setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.green))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_status)
                }
            }
        }
    }
}